#!/bin/bash
rm -rf /opt/module/src/x264/videolan
git clone https://code.videolan.org/videolan/x264.git /opt/module/src/x264/videolan
# 修改为自己的NDK的解压路径
cd /opt/module/src/x264/videolan
#linux r21e，ANDROID_NDK，我这里是在环境变量里配置了
NDK=/mnt/android_home/ndk/android-ndk-r28c

export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
API=21

function build_arm64
{
  ./configure \
    --prefix=$PREFIX \
    --disable-cli \
    --disable-asm \
    --enable-shared \
    --enable-pic \
    --host=$HOST \
    --cross-prefix=$CROSS_PREFIX \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic $OPTIMIZE_CFLAGS" \
    --extra-ldflags="$EXTRA_LDFLAGS" \


        make clean
        make
        make install
}

function build_armv7a
{
  ./configure \
    --prefix=$PREFIX \
    --disable-cli \
    --disable-asm  \
    --enable-shared \
    --enable-pic \
    --host=$HOST \
    --cross-prefix=$CROSS_PREFIX \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic $OPTIMIZE_CFLAGS" \

        make clean
        make
        make install
}



CPU=armv8-a
API=21
HOST=aarch64-linux-android
export CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++
SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
export CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
PREFIX=$(pwd)/android/$CPU
OPTIMIZE_CFLAGS="-march=$CPU"
EXTRA_LDFLAGS="-Wl,-z,max-page-size=65536 -Wl,-z,common-page-size=65536"
build_arm64


CPU=armv7-a
API=21
HOST=armv7a-linux-android
export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang
export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++
SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
export CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
PREFIX=$(pwd)/android/$CPU
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
build_armv7a